package team.chess.ui;

import team.chess.client.Client;
import team.chess.client.JoinRoom;
import team.chess.control.MyPanel;
import team.chess.dao.Login;
import team.chess.dao.SignUp;
import team.chess.server.CreateRoom;
import team.chess.server.Server;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;

/**
 * 菜单管理类
 * 1.主菜单：
 *          1.2.设置菜单；
 * 2.二级主菜单：
 *          2.1.单人游戏页面；
 *          2.2.网络登录页面：
 *                      2.2.1.网络游戏页面
 *                      2.2.2.账户注册页面
 */
public class Menu extends JPanel{

    String saccount = null;
    String spassword = null;
    boolean flag = false;
    public Server server = null;

    Image Icon = null;

    //一级菜单： 开始， 设置， 退出
    JFrame frame_1 = new JFrame();
    JPanel jp_1 = new JPanel();    //创建JPanel对象
    JButton btn_1_1 = new JButton("开 始");    //创建JButton对象
    JButton btn_1_2 = new JButton("设 置");    //创建JButton对象
    JButton btn_1_3 = new JButton("退 出");    //创建JButton对象

    //二级菜单： 单人模式， 多人模式， 返回
    JPanel jp_2 = new JPanel();    //创建JPanel对象
    JFrame frame_2 = new JFrame();
    JButton btn_2_1 = new JButton("单 人 模 式");      //创建JButton对象
    JButton btn_2_2 = new JButton("多 人 模 式");      //创建JButton对象
    JButton btn_2_3 = new JButton("返 回");         //创建JButton对象

    //网络对战登录: 账号、密码框， 登录， 返回
    JPanel jp_3 = new JPanel();    //创建JPanel对象
    JFrame frame_3 = new JFrame();
    JTextField textField_3_1 = new JTextField();
    JPasswordField passwordField_3_1 = new JPasswordField();
    JLabel label_3_1 = new JLabel("账号:");
    JLabel label_3_2 = new JLabel("密码:");
    JButton btn_3_1 = new JButton("登 录");      //创建JButton对象
    JButton btn_3_2 = new JButton("返 回");      //创建JButton对象
    JButton btn_3_3 = new JButton("注册");

    //注册界面（~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~）
    JFrame frame_4 = new JFrame();
    JPanel jp_4 = new JPanel();    //创建JPanel对象
    JLabel label_4_1 = new JLabel("账号:");
    JLabel label_4_2 = new JLabel("密码:");
    JLabel label_4_3 = new JLabel("确认密码:");
    JTextField textField_4_1 = new JTextField();
    JPasswordField passwordField_4_1 = new JPasswordField();
    JPasswordField passwordField_4_2 = new JPasswordField();
    JButton btn_4_1 = new JButton("确 认");    //创建JButton对象
    JButton btn_4_2 = new JButton("退 出");    //创建JButton对象

    //设置菜单
    JFrame frame_5 = new JFrame();
    JPanel jp_5 = new JPanel();    //创建JPanel对象
    JButton btn_5_1 = new JButton("背 景");    //创建JButton对象
    JButton btn_5_2 = new JButton("音 乐");    //创建JButton对象
    JButton btn_5_3 = new JButton("返 回");    //创建JButton对象

    //多人房间
    JFrame frame_6 = new JFrame();
    JPanel jp_6 = new JPanel();    //创建JPanel对象
    JButton btn_6_1 = new JButton("创 建 房 间");    //创建JButton对象
    JButton btn_6_2 = new JButton("加 入 房 间");    //创建JButton对象
    JButton btn_6_3 = new JButton("退 出 登 录");    //创建JButton对象

    //创建房间
    JFrame frame_7 = new JFrame();
    JPanel jp_7 = new JPanel();    //创建JPanel对象
    JLabel label_7_1 = new JLabel("当前主机账户为：");
    JLabel label_7_2 = new JLabel("未有对手加入房间");
    JButton btn_7_1 = new JButton("开 始 游 戏");    //创建JButton对象
    JButton btn_7_2 = new JButton("退 出 房 间");    //创建JButton对象
//    JButton btn_7_3 = new JButton("退 出 登 录");    //创建JButton对象

    //加入房间
    JFrame frame_8 = new JFrame();
    JPanel jp_8 = new JPanel();    //创建JPanel对象
    JLabel label_8_1 = new JLabel("请输入主机的账户：");
    JLabel label_8_2 = new JLabel("当 前 未 加 入 房 间");
    JTextField textField_8_1 = new JTextField();
    JButton btn_8_1 = new JButton("加 入 房 间");    //创建JButton对象
    JButton btn_8_2 = new JButton("退 出 房 间");    //创建JButton对象

    //单人游戏界面
    JFrame frame = new JFrame();
    JButton button_1 = new JButton("返 回");


    public Menu() {

        try {
            Icon = ImageIO.read(new File("src/team/chess/img/r_m.png"));
        } catch (IOException e) {
            e.printStackTrace();
        }

        //主菜单
        {

            frame_1.setSize(600, 800);
            frame_1.setTitle("中国象棋");
            frame_1.setLocationRelativeTo(null);
            frame_1.setIconImage(Icon);

            jp_1.setLayout(null);

            btn_1_1.setFocusPainted(false);
            btn_1_1.setFont(new Font("楷体",Font.BOLD,24));
            jp_1.add(btn_1_1);
            btn_1_1.setBounds(200, 200, 200, 50);

            btn_1_2.setFocusPainted(false);
            btn_1_2.setFont(new Font("楷体",Font.BOLD,24));
            jp_1.add(btn_1_2);
            btn_1_2.setBounds(200, 350, 200, 50);

            btn_1_3.setFocusPainted(false);
            btn_1_3.setFont(new Font("楷体",Font.BOLD,24));
            jp_1.add(btn_1_3);
            btn_1_3.setBounds(200, 500, 200, 50);

            frame_1.add(jp_1);
            frame_1.setVisible(true);
            frame_1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        }

        //二级主菜单
        {
            frame_2.setSize(600, 800);
            frame_2.setTitle("中国象棋");
            frame_2.setLocationRelativeTo(null);
            frame_2.setIconImage(Icon);

            jp_2.setLayout(null);

            btn_2_1.setFocusPainted(false);
            btn_2_1.setFont(new Font("楷体",Font.BOLD,24));
            jp_2.add(btn_2_1);
            btn_2_1.setBounds(200, 200, 200, 50);

            btn_2_2.setFocusPainted(false);
            btn_2_2.setFont(new Font("楷体",Font.BOLD,24));
            jp_2.add(btn_2_2);
            btn_2_2.setBounds(200, 350, 200, 50);

            btn_2_3.setFocusPainted(false);
            btn_2_3.setFont(new Font("楷体",Font.BOLD,24));
            jp_2.add(btn_2_3);
            btn_2_3.setBounds(200, 500, 200, 50);

            frame_2.add(jp_2);
            frame_2.setVisible(false);
            frame_2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        }

        //登陆界面
        {
            frame_3.setSize(600, 800);
            frame_3.setTitle("登录");
            frame_3.setLocationRelativeTo(null);
            frame_3.setIconImage(Icon);

            jp_3.setLayout(null);

            label_3_1.setFont(new Font("楷体",Font.BOLD,24));
            jp_3.add(label_3_1);
            label_3_1.setBounds(130,150,70,50);

            label_3_2.setFont(new Font("楷体",Font.BOLD,24));
            jp_3.add(label_3_2);
            label_3_2.setBounds(130,300,70,50);

            jp_3.add(textField_3_1);
            textField_3_1.setBounds(150,200,300,30);

            jp_3.add(passwordField_3_1);
            passwordField_3_1.setBounds(150,350,300,30);

            btn_3_1.setFocusPainted(false);
            btn_3_1.setFont(new Font("楷体",Font.BOLD,24));
            jp_3.add(btn_3_1);
            btn_3_1.setBounds(150, 500, 100, 50);

            btn_3_2.setFocusPainted(false);
            btn_3_2.setFont(new Font("楷体",Font.BOLD,24));
            jp_3.add(btn_3_2);
            btn_3_2.setBounds(350, 500, 100, 50);

            btn_3_3.setFocusPainted(false);
            jp_3.add(btn_3_3);
            btn_3_3.setBounds(400, 400, 60, 40);

            frame_3.add(jp_3);
            frame_3.setVisible(false);
            frame_3.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        }

        //注册界面
        {
            frame_4.setSize(600, 450);
            frame_4.setTitle("注册");
            frame_4.setLocationRelativeTo(null);
            frame_4.setIconImage(Icon);

            jp_4.setLayout(null);

            label_4_1.setFont(new Font("楷体",Font.BOLD,24));
            jp_4.add(label_4_1);
            label_4_1.setBounds(130,0,70,50);

            label_4_2.setFont(new Font("楷体",Font.BOLD,24));
            jp_4.add(label_4_2);
            label_4_2.setBounds(130,100,70,50);

            label_4_3.setFont(new Font("楷体",Font.BOLD,24));
            jp_4.add(label_4_3);
            label_4_3.setBounds(110,200,120,50);

            jp_4.add(textField_4_1);
            textField_4_1.setBounds(150,50,300,30);

            jp_4.add(passwordField_4_1);
            passwordField_4_1.setBounds(150,150,300,30);

            jp_4.add(passwordField_4_2);
            passwordField_4_2.setBounds(150,250,300,30);

            btn_4_1.setFocusPainted(false);
            btn_4_1.setFont(new Font("楷体",Font.BOLD,24));
            jp_4.add(btn_4_1);
            btn_4_1.setBounds(150, 320, 100, 50);

            btn_4_2.setFocusPainted(false);
            btn_4_2.setFont(new Font("楷体",Font.BOLD,24));
            jp_4.add(btn_4_2);
            btn_4_2.setBounds(350, 320, 100, 50);


            frame_4.add(jp_4);
            frame_4.setVisible(false);
            frame_4.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        }

        //设置菜单
        {
            frame_5.setSize(600, 800);
            frame_5.setTitle("游戏设置");
            frame_5.setLocationRelativeTo(null);
            frame_5.setIconImage(Icon);

            jp_5.setLayout(null);

            btn_5_1.setFocusPainted(false);
            btn_5_1.setFont(new Font("楷体",Font.BOLD,24));
            jp_5.add(btn_5_1);
            btn_5_1.setBounds(200, 200, 200, 50);

            btn_5_2.setFocusPainted(false);
            btn_5_2.setFont(new Font("楷体",Font.BOLD,24));
            jp_5.add(btn_5_2);
            btn_5_2.setBounds(200, 350, 200, 50);

            btn_5_3.setFocusPainted(false);
            btn_5_3.setFont(new Font("楷体",Font.BOLD,24));
            jp_5.add(btn_5_3);
            btn_5_3.setBounds(200, 500, 200, 50);

            frame_5.add(jp_5);
            frame_5.setVisible(false);
            frame_5.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        }

        //多人房间
        {
            frame_6.setSize(600, 800);
            frame_6.setTitle("多人游戏");
            frame_6.setLocationRelativeTo(null);
            frame_6.setIconImage(Icon);

            jp_6.setLayout(null);

            btn_6_1.setFocusPainted(false);
            btn_6_1.setFont(new Font("楷体",Font.BOLD,24));
            jp_6.add(btn_6_1);
            btn_6_1.setBounds(200, 200, 200, 50);

            btn_6_2.setFocusPainted(false);
            btn_6_2.setFont(new Font("楷体",Font.BOLD,24));
            jp_6.add(btn_6_2);
            btn_6_2.setBounds(200, 350, 200, 50);

            btn_6_3.setFocusPainted(false);
            btn_6_3.setFont(new Font("楷体",Font.BOLD,24));
            jp_6.add(btn_6_3);
            btn_6_3.setBounds(200, 500, 200, 50);


            frame_6.add(jp_6);
            frame_6.setVisible(false);
            frame_6.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        }

        //创建房间
        {
            frame_7.setSize(600, 800);
            frame_7.setTitle("创建房间");
            frame_7.setLocationRelativeTo(null);
            frame_7.setIconImage(Icon);

            jp_7.setLayout(null);

            label_7_1.setFont(new Font("楷体",Font.BOLD,24));
            jp_7.add(label_7_1);
            label_7_1.setBounds(200,200,250,50);

            btn_7_1.setFocusPainted(false);
            btn_7_1.setFont(new Font("楷体",Font.BOLD,24));
            jp_7.add(btn_7_1);
            btn_7_1.setBounds(200, 300, 200, 50);

            label_7_2.setFont(new Font("楷体",Font.BOLD,24));
            jp_7.add(label_7_2);
            label_7_2.setBounds(200,420,250,50);

            btn_7_2.setFocusPainted(false);
            btn_7_2.setFont(new Font("楷体",Font.BOLD,24));
            jp_7.add(btn_7_2);
            btn_7_2.setBounds(200, 550, 200, 50);


            frame_7.add(jp_7);
            frame_7.setVisible(false);
            frame_7.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        }

        //加入房间
        {
            frame_8.setSize(600, 800);
            frame_8.setTitle("加入房间");
            frame_8.setLocationRelativeTo(null);
            frame_8.setIconImage(Icon);

            jp_8.setLayout(null);

            label_8_1.setFont(new Font("楷体",Font.BOLD,24));
            jp_8.add(label_8_1);
            label_8_1.setBounds(180,100,300,50);

            jp_8.add(textField_8_1);
            textField_8_1.setBounds(180,200,200,30);

            btn_8_1.setFocusPainted(false);
            btn_8_1.setFont(new Font("楷体",Font.BOLD,24));
            jp_8.add(btn_8_1);
            btn_8_1.setBounds(200, 300, 200, 50);

            label_8_2.setFont(new Font("楷体",Font.BOLD,24));
            jp_8.add(label_8_2);
            label_8_2.setBounds(180,420,300,50);

            btn_8_2.setFocusPainted(false);
            btn_8_2.setFont(new Font("楷体",Font.BOLD,24));
            jp_8.add(btn_8_2);
            btn_8_2.setBounds(200, 550, 200, 50);

            frame_8.add(jp_8);
            frame_8.setVisible(false);
            frame_8.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        }
    }

    public void clicked(){

        //主菜单
        {
            btn_1_1.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    System.out.println("开始");
                    frame_1.setVisible(false);
                    frame_2.setVisible(true);
                }
            });

            btn_1_2.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    System.out.println("设置");
                    frame_1.setVisible(false);
                    frame_5.setVisible(true);
                }
            });

            btn_1_3.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    System.out.println("退出");
                    System.exit(0);
                }
            });
        }

        //二级主菜单
        {
            btn_2_1.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    System.out.println("单人");
                    frame_2.setVisible(false);
                    gameStart();
                }
            });

            btn_2_2.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    System.out.println("多人");
                    frame_2.setVisible(false);
                    frame_3.setVisible(true);
                }
            });

            btn_2_3.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    System.out.println("返回");
                    frame_2.setVisible(false);
                    frame_1.setVisible(true);
                }
            });
        }

        //登录页面
        {
            btn_3_1.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    String account = textField_3_1.getText();
                    String password = new String(passwordField_3_1.getPassword());

                    if (account.length()!=0 && password.length()!=0) {
                        Login login = new Login(account,password);
                        if (login.Login()){
                            JOptionPane.showMessageDialog(jp_3,"登录成功","提示",JOptionPane.WARNING_MESSAGE);

                            saccount = account;
                            spassword = password;
                            System.out.println(saccount);
                            frame_6.setVisible(true);
                            frame_3.setVisible(false);
                        }else{
                            JOptionPane.showMessageDialog(jp_3,"用户名或密码错误（或请联网后重试）","提示",JOptionPane.WARNING_MESSAGE);
                        }
                    }else {
                        JOptionPane.showMessageDialog(jp_3,"请输入用户名和密码","提示",JOptionPane.WARNING_MESSAGE);
                    }
                }
            });

            btn_3_2.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    System.out.println("返回");
                    frame_3.setVisible(false);
                    frame_2.setVisible(true);
                }
            });

            btn_3_3.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    System.out.println("注册");
                    frame_4.setVisible(true);
                }
            });
        }

        //注册菜单
        {
            //注册接口~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            btn_4_1.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
//                    System.out.println(passwordField_4_1.getPassword());
//                    System.out.println(passwordField_4_2.getPassword());
                    if (String.valueOf(passwordField_4_1.getPassword()).equals(String.valueOf(passwordField_4_2.getPassword()))){
//                        System.out.println(String.valueOf(passwordField_4_1.getPassword())+String.valueOf(passwordField_4_2.getPassword()));
                        SignUp signUp = new SignUp(textField_4_1.getText(),String.valueOf(passwordField_4_1.getPassword()));
                        if (signUp.signUp()){
                            JOptionPane.showMessageDialog(jp_4, "注册成功", "提示",JOptionPane.WARNING_MESSAGE);
                        }else{
                            JOptionPane.showMessageDialog(jp_4, "该用户已存在", "提示",JOptionPane.WARNING_MESSAGE);
                        }
                    }else {
                        JOptionPane.showMessageDialog(jp_4, "确认密码与密码不一致", "提示",JOptionPane.WARNING_MESSAGE);
                    }
                    System.out.println("确认注册");
                }
            });

            btn_4_2.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    System.out.println("退出");
                    frame_4.setVisible(false);
                }
            });
        }

        //设置菜单
        {
            btn_5_1.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    System.out.println("背景");
                }
            });

            btn_5_2.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    System.out.println("音乐");
                }
            });

            btn_5_3.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    System.out.println("返回");
                    frame_5.setVisible(false);
                    frame_1.setVisible(true);
                }
            });
        }

        //多人房间
        {
            btn_6_1.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    label_7_1.setText("当前主机账户为："+ saccount);
                    CreateRoom room = new CreateRoom(saccount);
                    Server server = room.createRoom();
                    server.start();
                    frame_7.setVisible(true);
                    frame_6.setVisible(false);
                    new Thread(){
                        @Override
                        public void run() {
                            while (server.socket==null||!server.socket.isConnected()){
                                try {
                                    sleep(100);
                                } catch (InterruptedException ex) {
                                    ex.printStackTrace();
                                }
                            }
                            Menu.this.server = server;
                            flag = true;
                            label_7_2.setText("对手已加入房间");
                        }
                    }.start();
                }
            });

            btn_6_2.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {

                    frame_8.setVisible(true);
                    frame_6.setVisible(false);
                }
            });

            btn_6_3.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    System.out.println("退出登录");
                    frame_6.setVisible(false);
                    frame_3.setVisible(true);
                }
            });
        }

        //创建房间
        {
            btn_7_1.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    System.out.println("多人");
                    if (flag){
                        try {
                            OutputStream os = server.socket.getOutputStream();
                            PrintWriter pw = new PrintWriter(os);
                            pw.write("Game Start\n");
                            pw.flush();
                            System.out.println("Game Start");
                        } catch (IOException ex) {
                            ex.printStackTrace();
                        }
                        gameStartOnlineHost(server);
                        frame_7.setVisible(false);
                    }else {
                        JOptionPane.showMessageDialog(jp_7,"未有对手加入房间","提示",JOptionPane.WARNING_MESSAGE);
                    }

                }
            });

            btn_7_2.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    frame_6.setVisible(true);
                    frame_7.setVisible(false);
                }
            });

        }

        //加入房间
        {
            btn_8_1.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    JoinRoom room = new JoinRoom(saccount,textField_8_1.getText());
                    Client client = room.joinRoom();
                    client.start();
                    new Thread(){
                        @Override
                        public void run() {
                            while (true){
                                if (client.socket.isConnected()){
                                    label_8_2.setText("当前加入"+textField_8_1.getText()+"的房间");
                                    break;
                                }
                            }
                            try {
                                InputStream is = null;
                                InputStreamReader isr = null;
                                BufferedReader br = null;
                                String info = null;
                                is = client.socket.getInputStream();
                                isr = new InputStreamReader(is);
                                br = new BufferedReader(isr);

                                while (true){
                                    if ((info= br.readLine()) != null){
                                        System.out.println("Get Game Start");
                                        frame_8.setVisible(false);
                                        gameStartOnlineClient(client);
                                        break;
                                    }
                                }

                            } catch (IOException ex) {
                                ex.printStackTrace();
                            }
                        }
                    }.start();
                }
            });

            btn_8_2.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    frame_8.setVisible(false);
                    frame_6.setVisible(true);
                }
            });
        }

        //单人游戏页面
        {
            button_1.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    System.out.println("返回");
                    frame.setVisible(false);
                    frame_2.setVisible(true);
                }
            });
        }
    }

    public void gameStart() {

        //单人游戏页面

        frame.setSize(1200,955);
        frame.setLocationRelativeTo(null);                      //窗口置中显示
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);   //关闭窗口时停止程序运行
        frame.setTitle("中国象棋");

        frame.setIconImage(Icon);
        MyPanel panel = new MyPanel();
        panel.setLayout(null);
        frame.add(panel);
        panel.mouseAction();
        panel.CreatQieces();

        button_1.setFocusPainted(false);
        button_1.setFont(new Font("楷体",Font.BOLD,24));
        panel.add(button_1);
        button_1.setBounds(1000, 800, 100, 50);
        frame.setVisible(true);
    }

    public void gameStartOnlineHost(Server server) {

        //多人游戏  --主机端

        frame.setSize(1200,955);
        frame.setLocationRelativeTo(null);                      //窗口置中显示
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);   //关闭窗口时停止程序运行
        frame.setTitle("中国象棋");

        frame.setIconImage(Icon);
        MyPanel panel = new MyPanel(server);
        panel.setLayout(null);
        frame.add(panel);
        panel.mouseAction();
        panel.CreatQieces();

        button_1.setFocusPainted(false);
        button_1.setFont(new Font("楷体",Font.BOLD,24));
        panel.add(button_1);
        button_1.setBounds(1000, 800, 100, 50);
        frame.setVisible(true);
    }

    public void gameStartOnlineClient(Client client) {

        //多人游戏 --客户端

        frame.setSize(1200,955);
        frame.setLocationRelativeTo(null);                      //窗口置中显示
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);   //关闭窗口时停止程序运行
        frame.setTitle("中国象棋");

        frame.setIconImage(Icon);
        MyPanel panel = new MyPanel(client);
        panel.setLayout(null);
        frame.add(panel);
        panel.mouseAction();
        panel.CreatQieces();

        button_1.setFocusPainted(false);
        button_1.setFont(new Font("楷体",Font.BOLD,24));
        panel.add(button_1);
        button_1.setBounds(1000, 800, 100, 50);
        frame.setVisible(true);
    }
}
